<template>
  <div class="home page">
    <div class="header">
      <yf-slide :items="bannerList" class="slide"></yf-slide>
      <yf-tab :tabs="tabs" class="tab"></yf-tab>
    </div>
    <div class="notice" v-if="notice">
      {{notice.content}}
      <span class="date">{{parseTime(notice.time)}}</span>
    </div>
    <div class="main">
      <blocks :blocks="blocks" class="block"></blocks>
    </div>
  </div>
</template>

<script>
import yfSlide from '../../components/base/yf-slide'
import yfTab from '../../components/base/yf-tab'
import blocks from '../../components/blocks'
import { mapState } from 'vuex'
import { LEVELS } from '../../const'
import { banner, notice, sumCheck } from '../../api/home'
import { parseTime } from '@/util/time'
import { showConfirm } from '@/dialog'
export default {
  components: {
    yfSlide,
    yfTab,
    blocks
  },
  created () {
    banner().then(res => {
      this.bannerList = res.data
    })
    notice().then(res => {
      this.notice = res.data
    })
    sumCheck().then(res => {
      const bus0 = res.extra.bus0
      const bus1 = res.extra.bus1
      const cost = res.extra.cost
      const goods = res.extra.goods
      const todo = res.extra.todo
      const img = res.extra.img
      let str = ''
      let show = false
      if (bus0 > 0) {
        str += `请假审核(${bus0})\r\n`
        show = true
      }
      if (bus1 > 0) {
        str += `出差审核(${bus1})\r\n`
        show = true
      }
      if (cost > 0) {
        str += `费用审核(${cost})\r\n`
        show = true
      }
      if (goods > 0) {
        str += `物料审核(${goods})\r\n`
        show = true
      }
      if (todo > 0) {
        str += `计划考核(${todo})\r\n`
        show = true
      }
      if (img > 0) {
        str += `晒单考核(${img})\r\n`
        // 暂时不显示
        // show = true
      }
      if (show) {
        showConfirm('待办事项', str)
      }
    })
  },
  methods: {
    parseTime (time) {
      return parseTime(time, '{y}-{m}-{d}')
    }
  },
  computed: {
    ...mapState({
      levelId: state => state.user.levelId
    }),
    tabs () {
      if (this.levelId === LEVELS.SHOP) {
        return this.SHOP_TAB
      }
      if (this.levelId === LEVELS.BUS) {
        return this.BUS_TAB
      }
      if (this.levelId > LEVELS.BUS) {
        return this.MANAGER_TAB
      }
      return []
    },
    blocks () {
      if (this.levelId === LEVELS.SHOP) {
        return this.SHOP_BLOCK
      }
      if (this.levelId === LEVELS.BUS) {
        return this.BUS_BLOCK
      }
      if (this.levelId === LEVELS.MANAGER) {
        return this.MANAGER_BLOCK
      }
      if (this.levelId > LEVELS.MANAGER) {
        return this.MANAGER_BLOCK.concat(this.MANAGER1_BLOCK)
      }
      return []
    }
  },
  data () {
    return {
      notice: null,
      bannerList: [],
      SHOP_TAB: [
        {
          name: '推广',
          path: '/share',
          icon: 'iconiconfonterweima'
        },
        {
          name: '会员',
          path: '/user',
          icon: 'iconpengyou'
        },
        {
          name: '审核',
          path: '/order/img/list',
          icon: 'icontuiguangxinxi'
        },
        {
          name: '我的',
          path: '/user/info',
          icon: 'iconxiaoshouguanli'
        }
      ],
      BUS_TAB: [
        {
          name: '今日工作',
          path: '/todo/record?today=true&type=0',
          icon: 'iconkaoherenwujihua'
        },
        {
          name: '周计划',
          path: '/plan',
          icon: 'icontime'
        },
        // {
        //   name: '药店店员',
        //   path: '/user',
        //   img: require('./yy.png')
        // },
        {
          name: '我的',
          path: '/user/info',
          icon: 'iconxiaoshouguanli'
        },
        {
          name: '推广',
          path: '/share',
          icon: 'iconiconfonterweima'
        }
      ],
      SHOP_BLOCK: [
        {
          name: '销售晒单',
          icon: 'iconstack',
          info: '销售票据拍照',
          path: '/order/img?pointType=2',
          active: false
        },
        {
          name: '暂未开放',
          icon: 'iconstack',
          info: '',
          path: null
        },
        {
          name: '暂未开放',
          icon: 'iconstack',
          info: '',
          path: null
        }
      ],
      BUS_BLOCK: [
        {
          name: '费用申请',
          info: '申请费用',
          icon: 'iconjiage-copy',
          path: '/apply/cost',
          active: false
        },
        {
          name: '物料申请',
          info: '申请物料',
          icon: 'iconwuliaoguanli',
          path: '/apply/goods'
        },
        {
          name: '出差申请',
          info: '申请出差',
          icon: 'iconchucha',
          path: '/apply/bus/apply?type=1'
        },
        {
          name: '请假申请',
          info: '申请假期',
          icon: 'iconshiwuzhongxin_qingjia',
          path: '/apply/bus/apply/leave?type=0'
        },
        {
          name: '建议需求',
          info: '提交建议',
          icon: 'iconkaohejilu',
          path: '/apply/advise',
          active: false
        },
        {
          name: '工作路线',
          info: '管理工作路线',
          icon: 'iconic_saleperformance',
          path: '/route/index?type=0',
          active: false
        },
        {
          name: '药店管理',
          info: '管理药店',
          icon: 'iconruntongyiyaoyihuifu_yiyaodian',
          path: '/route/index?type=1',
          active: false
        },
        {
          name: '学校管理',
          info: '管理学校',
          icon: 'iconxuexiao2',
          path: '/route/index?type=2',
          active: false
        },
        {
          name: '销量统计',
          info: '销量统计',
          icon: 'iconic_saleperformance',
          path: '/sale',
          active: false
        },
        {
          name: '药店晒单',
          info: '药店晒单',
          icon: 'iconkaohejilu',
          path: '/order/img/list',
          active: false
        },
        {
          name: '药店会员',
          info: '药店会员',
          icon: 'iconruntongyiyaoyihuifu_yiyaodian',
          path: '/user/sum',
          active: false
        },
        {
          name: '暂未开放',
          icon: 'iconstack',
          info: '',
          path: null
        }
      ],
      MANAGER_TAB: [
        // {
        //   name: '推广',
        //   path: '/share',
        //   img: require('./qr.png')
        // },
        // {
        //   name: '考核',
        //   path: '/score',
        //   img: require('./rc.png')
        // },
        {
          name: '今日计划',
          path: '/todo/record?today=true&type=0',
          icon: 'iconkaoherenwujihua'
        },
        {
          name: '今日考核',
          path: '/todo/record?today=true&type=1&top=true',
          icon: 'icontuiguangxinxi'
        },
        {
          name: '周计划',
          path: '/plan',
          icon: 'iconrili'
        },
        {
          name: '推广',
          path: '/share',
          icon: 'iconiconfonterweima'
        },
        // {
        //   name: '团队',
        //   path: '/user',
        //   img: require('./users.png')
        // },
        {
          name: '我的',
          path: '/user/info',
          icon: 'iconxiaoshouguanli'
        }
      ],
      MANAGER_BLOCK: [
        {
          name: '费用申请',
          info: '申请费用',
          icon: 'iconjiage-copy',
          path: '/apply/cost',
          active: false
        },
        {
          name: '物料申请',
          info: '物料申请',
          icon: 'iconwuliaoguanli',
          path: '/apply/goods',
          active: false
        },
        {
          name: '出差申请',
          info: '出差申请',
          icon: 'iconchucha',
          path: '/apply/bus?type=1'
        },
        {
          name: '请假申请',
          info: '请假申请',
          icon: 'iconshiwuzhongxin_qingjia',
          path: '/apply/bus/apply/leave?type=0'
        },
        {
          name: '工作路线',
          info: '管理工作路线',
          icon: 'iconic_saleperformance',
          path: '/route/index?type=0',
          active: false
        },
        {
          name: '药店管理',
          info: '管理药店',
          icon: 'iconruntongyiyaoyihuifu_yiyaodian',
          path: '/route/index?type=1',
          active: false
        },
        {
          name: '学校管理',
          info: '管理学校',
          icon: 'iconxuexiao2',
          path: '/route/index?type=2',
          active: false
        },
        {
          name: '销量统计',
          info: '销量统计',
          icon: 'iconic_saleperformance',
          path: '/sale',
          active: false
        },
        {
          name: '计划统计',
          icon: 'iconstack',
          info: '',
          path: '/todo/sum',
          active: false
        }
      ],
      MANAGER1_BLOCK: [
        {
          name: '人员招聘',
          info: '招聘人员',
          icon: 'iconxiaoshouguanli',
          path: '/todo/hunt',
          active: false
        }
      ]
    }
  }
}
</script>

<style scoped lang="stylus">
  .home
    background-color #EFEFEF
    overflow scroll
    .header
      background-color #F5F4F7
      padding-bottom 0.68rem
      margin-bottom 0.2rem
      .tabs
        margin-top 0.77rem
    .notice
      overflow hidden
      background-color #f5f4f7
      font-size 14px
      line-height 20px
      margin 20px 0
      padding 10px 10px
      color #A1A1A1
      .date
        float right
        display block
        margin-top 5px
    .main
      background-color #F5F4F7
      padding 0 0.27rem
      padding-top 0.48rem
</style>
